package com.fudan.cfg.dataset;

import java.util.Map;

import com.fudan.cfg.base.DatasetDef;
import com.fudan.run.ctx.annotation.DatasetAdapter;

@DatasetAdapter("mysql")
public class MysqlFDataset extends DatasetDef{

	private String source;
	private String username;
	private String password;

	private String table;
	private String condition;
	private Integer partition=2;

	public MysqlFDataset(String name, String type) {
		super(name, type);
	}

	@Override
	public DatasetDef build(Map<String, Object> configuration) {
		this.source = (String) configuration.get("source");
		if(this.source!=null && !this.source.startsWith("jdbc:mysql://")) {
			this.source = "jdbc:mysql://"+this.source;
		}
		if(this.source!=null && !this.source.contains("?")) {
			this.source = this.source+"?useUnicode=true&characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2B8";
		}
		this.username = (String) configuration.get("username");
		this.password = (String) configuration.get("password");
		this.table = (String) configuration.get("table");
		this.condition = (String) configuration.get("condition");
		Object partitionDef = configuration.get("partition");
		if(partitionDef != null) {
			this.partition = (Integer) partitionDef;
		}
		return this;
	}

	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getTable() {
		return table;
	}

	public void setTable(String table) {
		this.table = table;
	}

	public Integer getPartition() {
		return partition;
	}

	public void setPartition(Integer partition) {
		this.partition = partition;
	}

	public String getCondition() {
		return condition;
	}

	public void setCondition(String condition) {
		this.condition = condition;
	}


}
